var n;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.HallMgr = undefined;
var r;
var DataManager = require("AA_DataManager");
var LogManager = require("AA_LogManager");
var ArrayUtils = require("AA_ArrayUtils");
var PlayerDataManager = require("AA_PlayerDataManager");
var Excel = require("AA_Excel");
var Const_Hall = require("AA_Const_Hall");
!function (e) {
  e.shop = "shop";
  e.unLockCiTiao = "unLockCiTiao";
  e.wuYongMap = "wuYongMap";
}(r || (r = {}));
var h = function (e) {
  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    t._secret_key = "hallSaveData";
    t._unLockCiTiao = [];
    t._wuYongMap = {};
    return t;
  }
  __extends(t, e);
  t.prototype.init = function (e) {
    undefined === e && (e = null);
    this._shopData = new Const_Hall.ShopSaveData();
    var t = this.getNowData(r.shop, e);
    this._shopData = __assign(__assign({}, this._shopData), t);
    var o = this.getNowData(r.unLockCiTiao, e);
    o && (this._unLockCiTiao = o);
    var n = this.getNowData(r.wuYongMap, e);
    n && (this._wuYongMap = n);
  };
  t.prototype.getNowData = function (e, t) {
    var o = null;
    if (t && (o = t[e])) {
      this.updateDataMap(e, o);
    } else {
      o = this._load(e);
    }
    return o;
  };
  Object.defineProperty(t.prototype, "shopData", {
    get: function () {
      if (!this._shopData) {
        this._shopData = new Const_Hall.ShopSaveData();
        LogManager.LogMgr.error("出现严重错误，商店数据取到了空值");
      }
      return this._shopData;
    },
    set: function (e) {
      this._shopData = e;
    },
    enumerable: false,
    configurable: true
  });
  t.prototype.SaveShopData = function () {
    this._save(r.shop, this._shopData);
  };
  t.prototype.CheckNextResetTime = function () {
    var e = new Date().getTime();
    (0 == this.shopData.nextResetTime || e >= this.shopData.nextResetTime) && this.ResetShopData();
    return Math.floor((this.shopData.nextResetTime - e) / 1e3);
  };
  t.prototype.ResetShopData = function () {
    var e = Excel.Excel.shopControl(1);
    var t = 0;
    var o = 0;
    if (this._shopData) {
      t = this._shopData.boxExp;
      o = this._shopData.boxLevel;
    }
    this._shopData = new Const_Hall.ShopSaveData();
    this._shopData.boxExp = t;
    this._shopData.boxLevel = o;
    var n = new Date();
    n.setHours(e.resetTime, 0, 0, 0);
    this.shopData.nextResetTime = n.getTime();
    this.ResetTodayShop();
  };
  t.prototype.ResetTodayShop = function () {
    this.shopData.todayShopArray = this.GetNewTodayShopData();
    this.SaveShopData();
  };
  t.prototype.GetNewTodayShopData = function () {
    var e = [2, 3];
    var t = [];
    var o = [];
    var n = [[], []];
    Excel.Excel.todayShop_all.forEach(function (e) {
      if (PlayerDataManager.PlayerDataMgr.GetEquipDataById(e.shuiguoId).isUnLock) {
        o.push(e);
        n[0].push(e.goldWeight);
        n[1].push(e.weight);
      }
    });
    for (var i = 0; i < e.length; i++) {
      for (var a = 0; a < e[i]; a++) {
        var r = o[ArrayUtils.default.getWeightRandom(n[i])];
        var c = new Const_Hall.TodayShopItemData();
        c.shopId = r.id;
        c.richType = i + 1;
        c.canBuyCount = 1;
        c.discount = r.discount[Math.floor(Math.random() * r.discount.length)];
        if (i + 1 == Const_Hall.RichType.金币) {
          c.price = Math.floor(r.gold * c.discount);
        } else {
          c.price = Math.floor(r.diamond * c.discount);
        }
        t.push(c);
        c.price;
      }
    }
    return t;
  };
  t.prototype.GetCiTiaoIsLock = function (e) {
    return -1 != this._unLockCiTiao.indexOf(e);
  };
  t.prototype.SetCiTiaoIsLock = function (e) {
    if (-1 == this._unLockCiTiao.indexOf(e)) {
      this._unLockCiTiao.push(e);
      this._save(r.unLockCiTiao, this._unLockCiTiao);
    }
  };
  Object.defineProperty(t.prototype, "wuYongMap", {
    get: function () {
      this._wuYongMap || (this._wuYongMap = {});
      return this._wuYongMap;
    },
    enumerable: false,
    configurable: true
  });
  t.prototype.SaveWuYongMap = function () {
    this._save(r.wuYongMap, this._wuYongMap);
  };
  return t;
}(DataManager.default);
exports.HallMgr = h.getInstance();